package com.qf.kdxf.util.common;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.util.UUID;

public class UploadFile {

    public static String upload(MultipartFile imageFile, String path) {
        String filePath = null;
        try {
            // 获取上传的文件名
            String fileName = imageFile.getOriginalFilename();
            // 保存文件的路径
            filePath = path + UUID.randomUUID() + fileName;
            System.err.println(filePath);
            // 创建文件输出流
            File outputFile = new File(filePath);
            FileOutputStream fos = new FileOutputStream(outputFile);
            // 将音频字节流写入文件中
            fos.write(imageFile.getBytes());
            fos.flush();
            fos.close();
        } catch (Exception e) {
            System.out.println("异常");
        }
        return filePath;
    }
}
